
//  MyHomePageViewController.m
//  CommunityApp
//
//  Created by 秦乾龙 on 16/12/30.
//  Copyright © 2016年 秦乾龙. All rights reserved.
//

#import "MyHomePageViewController.h"
#import "AFNetworking.h"//主要用于网络请求方法
#import "UIKit+AFNetworking.h"//里面有异步加载图片的方法
#import "AFHTTPSessionManager.h"
#import "UIButton+WebCache.h"
#import "UIImageView+WebCache.h"
#import "NavView.h"
#import "User.h"
#import "ZYTableViewCell.h"
#import "SetViewController.h"
#import "sellerCenterViewController.h"
#import "HisCommentViewController.h"
#import "ZYButton.h"
#import "Article.h"
#import "ArticleWebViewController.h"
#import "TopicleWebViewController.h"
#import "GoodListViewController.h"
#import "ArticleViewController.h"
#import "TopicViewController.h"
#import "PublishArticleViewController.h"
#import "ZanGuoViewController.h"


#define kScreenW [UIScreen mainScreen].bounds.size.width
#define kScreenH [UIScreen mainScreen].bounds.size.height
#define kScale   ([UIScreen mainScreen].bounds.size.width)/750
@interface MyHomePageViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,retain)UITableView *mainTableView;
@property(nonatomic,retain) User *user;
@property(nonatomic,copy) NSMutableArray *tagArr;
@property(nonatomic,copy) NSMutableArray *articleArr;
@property(nonatomic,copy) Article *myStory;
@property(nonatomic,copy) UIButton *careBtn;
@property(nonatomic,copy) NSString *addressStr;
@end

@implementation MyHomePageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    DYLog(@"ussid%@",[UserData userid]);
    DYLog(@"token%@",[UserData usertoken]);
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
    self.view.backgroundColor = [UIColor grayColor];
    
    
    _mainTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, -21, ScreenW, ScreenH+21) style:UITableViewStyleGrouped];
    //    _mainTableView.bounces = NO;
    //    _mainTableView.alwaysBounceVertical = NO;
    _mainTableView.delegate = self;
    _mainTableView.dataSource = self;
    [self.view addSubview:_mainTableView];
    [self addRefreshHeader:_mainTableView];
    
    NavView *nav = [[NavView alloc]initWithTitle:@"" LeftImage:[ UIImage imageNamed:@"返回"]];
    [nav.leftBtn addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
    nav.frame = CGRectMake(0, 20, ScreenW, 44);
    nav.titleLable.textColor = [UIColor whiteColor];
    self.view.backgroundColor = [UIColor colorWithRed:32/255.0 green:32/255.0 blue:32/255.0 alpha:1.0f];
    nav.rightBtn.hidden = YES;
    [nav.rightBtn setTitle:@"菜单" forState:UIControlStateNormal];
    [self.view addSubview:nav];
    
}
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self request];
    self.navigationController.navigationBarHidden = YES;
}
- (void) viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    self.navigationController.navigationBarHidden = NO;
}
//下拉刷新
- (void)refresh {
    [super refresh];
    [self request];
}

- (void)request
{
    
    NSString *urlStr = [NSString stringWithFormat:@"%@/hytribe/getUserAllObject?o_user_id=%@", APIYIGOU,[UserData userid]];
    DYBaseRequest *request = [DYBaseRequest new];
    request.requestUrl = urlStr;
    [request dyBgStartWithCompletionBlockWithSuccess:^(YTKBaseRequest *request) {
        NSDictionary *allDic = [NSDictionary changeType:request.responseJSONObject];
        NSLog(@"11112222%@",allDic);
        _user = [[User alloc]initWithDic:allDic[@"data"][@"hyuser"]];
        _tagArr = allDic[@"data"][@"userTag"];
        _addressStr = allDic[@"data"][@"fhAddress"];
        _articleArr = allDic[@"data"][@"content"];
        _myStory =[Article mj_objectWithKeyValues:allDic[@"data"][@"mycontent"]];
        NSLog(@"2222221%@",allDic[@"data"][@"content"]);
        [_mainTableView reloadData];
        [_mainTableView.header endRefreshing];
    } error:^(YTKBaseRequest *request) {
        [_mainTableView.header endRefreshing];
    } failure:^(YTKBaseRequest *request) {
        [_mainTableView.header endRefreshing];
        [ViewFactory showErrorStrMsg:NETWORK_ERR];
    }];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 4;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section==0)
    {
        return 1;
    }
    else if (section==1)
    {
        return 1;
    }
    else if (section==2)
    {
        return 1;
    }
    return _articleArr.count;
}


- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString * identifier = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell)
    {
        cell =[[NSBundle mainBundle ]loadNibNamed:@"ZYTableViewCell" owner:nil options:nil][0];
    }
    //无色
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    if (indexPath.section==0)
    {
        CGFloat publicSpace = 30*kScale;
        UIImageView *backImageView = [[UIImageView alloc]init];
        [backImageView sd_setImageWithURL:[NSURL URLWithString:_user.headerImageUrl] width:ScreenW height:790*kScale];
        backImageView.frame = CGRectMake(0, 0, ScreenW, 790*kScale);
        [cell addSubview:backImageView];
        UIView *coverView = [[UIView alloc]init];
        coverView.frame = backImageView.frame;
        coverView.backgroundColor = [UIColor blackColor];
        coverView.alpha = 0.5;
        [cell addSubview:coverView];
        CGFloat headerImageH = 132*kScale;
        UIImageView *headerImage = [[UIImageView alloc]init];
        [headerImage sd_setImageWithURL:[NSURL URLWithString:_user.headerImageUrl]];
        NSLog(@"222%@",_user.headerImageUrl);
        headerImage.frame = CGRectMake(ScreenW/2-headerImageH/2,64+publicSpace, headerImageH, headerImageH);
        headerImage.layer.masksToBounds = YES; //没这句话它圆不起来
        headerImage.layer.cornerRadius = headerImageH/2.0;
        [cell addSubview:headerImage];
        CGFloat nameLableH = 42*kScale;
        CGFloat addressH = 30*kScale;
        UILabel *namelable = [[UILabel alloc]init];
        
        namelable.text= _user.name;
        CGSize nameLableSize = [namelable sizeThatFits:CGSizeMake(MAXFLOAT, nameLableH)];
        namelable.frame = CGRectMake(0,64+2*publicSpace+headerImageH, nameLableSize.width, nameLableH);
        namelable.center = CGPointMake(headerImage.center.x, 64+2*publicSpace+headerImageH+nameLableH/2);
        namelable.textColor = [UIColor whiteColor];
        namelable.textAlignment = NSTextAlignmentCenter;
        [cell addSubview:namelable];
        UIImageView *addressImg = [[UIImageView alloc]init];
        [addressImg setImage:[UIImage imageNamed:@"地址"]];
        addressImg.frame = CGRectMake(namelable.frame.origin.x+nameLableSize.width+20*kScale, 64+2*publicSpace+headerImageH+6*kScale, 21*kScale, addressH);
        [cell addSubview:addressImg];
        
        UILabel *addresslable = [[UILabel alloc]init];
        
        addresslable.text= _addressStr;
        addresslable.font = [UIFont systemFontOfSize:13];
        CGSize addresslableSize = [addresslable sizeThatFits:CGSizeMake(MAXFLOAT, nameLableH)];
        addresslable.frame = CGRectMake(addressImg.frame.origin.x+20*kScale+addressImg.frame.size.width, 64+2*publicSpace+headerImageH+6*kScale, addresslableSize.width, addressH);
        addresslable.textColor = [UIColor whiteColor];
        addresslable.textAlignment = NSTextAlignmentCenter;
        [cell addSubview:addresslable];
        if (_addressStr.length == 0) {
            addressImg.hidden = YES;
        } else {
            addressImg.hidden = NO;
        }
        //私信
        CGFloat privateLetterW = 136*kScale;
        CGFloat privateLetterH = 62*kScale;
        
        ZYButton *privateLetterBtn = [ZYButton buttonWithType:UIButtonTypeCustom];
        [privateLetterBtn setTitle:@"私信" forState:UIControlStateNormal];
        privateLetterBtn.titleLabel.font = [UIFont systemFontOfSize:15];
        [privateLetterBtn setTitleColor:ZallColorFromRGB(0x000000) forState:UIControlStateNormal];
        privateLetterBtn.layer.cornerRadius = privateLetterH/2;
        privateLetterBtn.frame = CGRectMake(0, 0, privateLetterW, privateLetterH);
        privateLetterBtn.center = CGPointMake(ScreenW-privateLetterW/2+31*kScale, headerImage.center.y);
        //        careBtn.layer.borderWidth = 2*kScale;
        privateLetterBtn.alpha = 0.8f;
        privateLetterBtn.backgroundColor = ZallColorFromRGB(0xffffff);
        [privateLetterBtn addTarget:self action:@selector(clickMsg) forControlEvents:UIControlEventTouchUpInside];
        [cell addSubview:privateLetterBtn];
        //活跃度
        ZYButton *activeBtn = [ZYButton buttonWithType:UIButtonTypeCustom];
        [activeBtn setTitle:[NSString stringWithFormat:@"%@",_user.active] forState:UIControlStateNormal];
        activeBtn.titleLabel.font = [UIFont systemFontOfSize:15];
        [activeBtn setTitleColor:ZallColorFromRGB(0x000000) forState:UIControlStateNormal];
        activeBtn.layer.cornerRadius = privateLetterH/2;
        activeBtn.frame = CGRectMake(0, 0, privateLetterW, privateLetterH);
        activeBtn.center = CGPointMake(ScreenW-privateLetterW/2+31*kScale, headerImage.center.y+privateLetterH+10*kScale);
        //        careBtn.layer.borderWidth = 2*kScale;
        activeBtn.alpha = 0.8f;
        activeBtn.backgroundColor = ZallColorFromRGB(0xffffff);
        [cell addSubview:activeBtn];
        UIImageView *activeImg = [[UIImageView alloc]init];
        activeImg.frame = CGRectMake(20*kScale, 16*kScale, 22*kScale, 30*kScale);
        activeImg.image = [UIImage imageNamed:@"热度"];
        [activeBtn addSubview:activeImg];
        UILabel *persionSignLable = [[UILabel alloc]init];
        persionSignLable.frame = CGRectMake(0, 0, 354*kScale, nameLableH);
        persionSignLable.font = [UIFont systemFontOfSize:13];
        persionSignLable.center =CGPointMake(ScreenW/2, 64+3*publicSpace+nameLableH+headerImageH+nameLableH/2);
        persionSignLable.text = _user.personSign;
        persionSignLable.textColor = [UIColor whiteColor];
        persionSignLable.textAlignment= NSTextAlignmentCenter;
        [cell addSubview:persionSignLable];
        
        CGFloat careBtnH = 48*kScale;
        _careBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_careBtn setTitle:@" 已关注  " forState:UIControlStateNormal];
        _careBtn.layer.cornerRadius  = 8*kScale;
        _careBtn.layer.masksToBounds = YES;
        _careBtn.titleLabel.textAlignment = NSTextAlignmentCenter;
        CGSize careBtnSize = [_careBtn sizeThatFits:CGSizeMake(MAXFLOAT, careBtnH)];
        _careBtn.frame = CGRectMake(0, 0, careBtnSize.width, careBtnH);
        _careBtn.center = CGPointMake(ScreenW/2, 64+4*publicSpace+headerImageH+2*nameLableH+careBtnH/2);
        //        careBtn.layer.borderWidth = 2*kScale;
       
            _careBtn.backgroundColor = ZallColorFromRGB(0x9e9e9e);
            _careBtn.enabled = NO;
     
        
        
        [_careBtn addTarget:self action:@selector(careBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [cell addSubview:_careBtn];
        
        CGFloat tagSignViewH = 34*kScale;
        UIView *tagSignView = [[UIView alloc]init];
        
        
        
        CGFloat tagSignViewW = 0;
        if (_tagArr.count>0) {
            if (_tagArr.count<3)
            {
                for (int i=0; i<_tagArr.count; i++)
                {
                    UILabel *tagLable = [[UILabel alloc]init];
                    tagLable.text = _tagArr[i][@"tag_name"];
                    CGFloat tagW = [tagLable sizeThatFits:CGSizeMake(MAXFLOAT, 34*kScale)].width;
                    tagLable.frame = CGRectMake(tagSignViewW, 0, tagW, tagSignViewH);
                    tagLable.textColor = [UIColor whiteColor];
                    tagLable.font = [UIFont systemFontOfSize:12];
                    tagLable.layer.masksToBounds = YES;
                    tagLable.layer.cornerRadius = tagSignViewH/2.0;
                    tagLable.backgroundColor = QINGColor;
                    tagSignViewW += tagW+8*kScale;
                    tagLable.textAlignment = NSTextAlignmentCenter;
                    [tagSignView addSubview:tagLable];
                    
                }
            }
            else
            {
                for (int i=0; i<3; i++)
                {
                    UILabel *tagLable = [[UILabel alloc]init];
                    tagLable.text = _tagArr[i][@"tag_name"];
                    CGFloat tagW = [tagLable sizeThatFits:CGSizeMake(MAXFLOAT, 34*kScale)].width;
                    tagLable.frame = CGRectMake(tagSignViewW, 0, tagW, tagSignViewH);
                    tagLable.textColor = [UIColor whiteColor];
                    tagLable.font = [UIFont systemFontOfSize:12];
                    tagLable.layer.masksToBounds = YES;
                    tagLable.layer.cornerRadius = tagSignViewH/2.0;
                    tagLable.backgroundColor = tagLable.backgroundColor = QINGColor;
                    tagSignViewW += tagW+8*kScale;
                    tagLable.textAlignment = NSTextAlignmentCenter;
                    [tagSignView addSubview:tagLable];
                    
                }
            }
        }
        tagSignView.frame = CGRectMake(0, 0, tagSignViewW-8*kScale, tagSignViewH);
        tagSignView.center = CGPointMake(ScreenW/2, 64+6*publicSpace+headerImageH+2*nameLableH+careBtnH+tagSignViewH/2);
        [cell addSubview:tagSignView];
        //        UIImageView *blackView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 64+7*publicSpace+headerImageH+2*nameLableH+careBtnH+tagSignViewH, ScreenW, 164*kScale)];
        UIImageView *blackView = [[UIImageView alloc]initWithFrame:CGRectMake(0, (790-164)*kScale, ScreenW, 164*kScale)];
        //        blackView.image = [UIImage imageNamed:@"组 36"];
        [cell addSubview:blackView];
        NSArray *signNameArr = [[NSArray alloc]initWithObjects:@"关注",@"粉丝",@"访客", nil];
        
        NSMutableArray *signCountArr = [[NSMutableArray alloc]initWithObjects:_user.follow,_user.personcount,_user.home_page_view_count, nil];
        NSLog(@"66666%@",_user.careCount);
        for (int i=0; i<signNameArr.count; i++)
        {
            CGFloat lableH = 42*kScale;
            UILabel *signNameLable = [[UILabel alloc]init];
            if (_user.collectionCount&&_user.careCount&&_user.personcount) {
                signNameLable.text = [NSString stringWithFormat:@"%@",signCountArr[i]];
                signNameLable.frame = CGRectMake(ScreenW/3*i, (164*kScale-50)/5*3, ScreenW/3, lableH);
                signNameLable.textAlignment=NSTextAlignmentCenter;
                signNameLable.textColor = [UIColor whiteColor];
            }
            
            
            
            [blackView addSubview:signNameLable];
            UILabel *signCountLable = [[UILabel alloc]init];
            
            signCountLable.text = [NSString stringWithFormat:@"%@",signNameArr[i]];
            
            signCountLable.frame = CGRectMake(ScreenW/3*i, (164*kScale-50)/5*3+30, ScreenW/3, lableH);
            signCountLable.font = [UIFont systemFontOfSize:14];
            signCountLable.textAlignment=NSTextAlignmentCenter;
            signCountLable.textColor = ZallColorFromRGB(0xffffff);
            [blackView addSubview:signCountLable];
            if (i>0) {
                UIView *lineView = [[UIView alloc]init];
                lineView.frame = CGRectMake(ScreenW/3*i, (164*kScale-50)/5*3, 2, 50);
                lineView.backgroundColor = ZallColorFromRGB(0xffffff);
                [blackView addSubview:lineView];
            }
        }
    }
    if (indexPath.section==1)
    {
        if (_myStory)
        {
            {
                CGFloat storeLableH = 23*kScale;
                UILabel *storyLable = [[UILabel alloc]init];
                storyLable.text = @"我的故事";
                storyLable.frame = CGRectMake(30*kScale, 40*kScale, ScreenW, storeLableH);
                [cell addSubview:storyLable];
                //        //右侧小箭头
                //        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
                CGFloat topH = 70*kScale+storeLableH;
                CGFloat headerImageH = 150*kScale;
                CGFloat headerImageW = 220*kScale;
                
                UIImageView *headerImage = [[UIImageView alloc]init];
                headerImage.frame = CGRectMake(30*kScale, topH, headerImageW, headerImageH);
                [headerImage sd_setImageWithURL:[NSURL URLWithString:_myStory.cover_img] width:140 height:140];
                headerImage.contentMode = UIViewContentModeScaleAspectFill;
                headerImage.layer.masksToBounds  = YES;
                //        headerImage.layer.cornerRadius = 8*kScale;
                [cell addSubview:headerImage];
                
                CGFloat titleImageW = 45*kScale;
                CGFloat titleImageH = 32*kScale;
                UIImageView *titleImage= [[UIImageView alloc]init];
                titleImage.image = [UIImage imageNamed:@"我的故事"];
                titleImage.frame = CGRectMake(headerImageW+2*30*kScale, headerImage.frame.origin.y+4*kScale,titleImageW, titleImageH);
                [cell addSubview:titleImage];
                UILabel *titleLable= [[UILabel alloc]init];
                titleLable.font = [UIFont systemFontOfSize:15];
                titleLable.text = _myStory.title;
                CGSize titleSize = [titleLable sizeThatFits:CGSizeMake(MAXFLOAT, 40*kScale)];
                titleLable.frame = CGRectMake(headerImageW+2*30*kScale+15*kScale+titleImageW, headerImage.frame.origin.y,ScreenW-(headerImageW+2*30*kScale+15*kScale+titleImageW+30*kScale), 40*kScale);
                [cell addSubview:titleLable];
                
                CGFloat maxH = 48;
                UILabel *introdocLable = [[UILabel alloc]init];
                introdocLable.font = [UIFont systemFontOfSize:13];
                introdocLable.numberOfLines = 3;
                //        introdocLable.lineBreakMode =  NSLineBreakByTruncatingTail;
                introdocLable.textColor = [UIColor colorWithRed:34/255.0 green:34/255.0 blue:34/255.0 alpha:1.0];
                NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc]init];
                style.lineSpacing = 5;
                introdocLable.text = _myStory.content_desc;
                introdocLable.textColor = [UIColor colorWithRed:136/255.0 green:136/255.0 blue:136/255.0 alpha:1.0];
                CGSize introSize = [introdocLable sizeThatFits:CGSizeMake(ScreenW-(headerImageW+3*30*kScale), MAXFLOAT)];
                
                //        NSDictionary *attributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:14], NSParagraphStyleAttributeName:style};
                //        introdocLable.attributedText = [[NSAttributedString alloc]initWithString:introdocLable.text attributes:attributes];
                
                if (introSize.height<maxH)
                {
                    introdocLable.frame = CGRectMake(headerImageW+2*30*kScale, headerImage.frame.origin.y+headerImageH-maxH, ScreenW-(headerImageW+3*30*kScale), maxH);
                }
                else
                {
                    introdocLable.frame = CGRectMake(headerImageW+2*30*kScale, headerImage.frame.origin.y+headerImageH-maxH, ScreenW-(headerImageW+3*30*kScale), maxH);
                }
                
                [cell addSubview:introdocLable];
                
            }
        }
        else
        {
            UILabel *makeStory = [[UILabel alloc] init];
            makeStory.text = @"点击创建我的故事";
            makeStory.frame = CGRectMake(0, 0, ScreenW, 100*kScale);
            makeStory.textAlignment = NSTextAlignmentCenter;
            [cell addSubview:makeStory];
        }
    }
    
    else if (indexPath.section==2)
    {
        CGFloat imageWidth = 40*kScale;
        CGFloat  width = 80*kScale;
        CGFloat  height = 42*kScale;
        CGFloat space = (ScreenW-60*kScale-4*width)/3;
        NSMutableArray *classNameArr = [NSMutableArray arrayWithObjects:@"文章",@"帖子",@"赞过",@"评论", nil];
        NSMutableArray *classImgArr = [NSMutableArray arrayWithObjects:@"文章",@"话题",@"赞过",@"评论黑", nil];
        for (int i = 0; i < 4; i++)
        {
            
            ZYButton *backBtn = [ZYButton buttonWithType:UIButtonTypeCustom];
            
            //            [backBtn setBackgroundImage:[UIImage imageNamed:classImgArr[i]] forState:UIControlStateNormal];
            backBtn.tag = i+10;
            
            backBtn.frame = CGRectMake(30*kScale+(width+space)*i, 0, width, 118*kScale);
            [backBtn addTarget:self action:@selector(classTitleClick:) forControlEvents:UIControlEventTouchUpInside];
            [cell addSubview:backBtn];
            
            UIImageView *classBtn = [[UIImageView alloc]init];
            classBtn.image = [UIImage imageNamed:classImgArr[i]];
            classBtn.frame = CGRectMake((width-imageWidth)/2, 20*kScale, imageWidth, imageWidth);
            [backBtn addSubview:classBtn];
            UILabel *classTitleLable = [[UILabel  alloc]init];
            classTitleLable.frame = CGRectMake(0, 20*kScale+imageWidth+10*kScale, width, height);
            classTitleLable.font = [UIFont systemFontOfSize:15];
            classTitleLable.text = classNameArr[i];
            classTitleLable.textColor = [UIColor blackColor];
            classTitleLable.textAlignment = NSTextAlignmentCenter;
            [backBtn addSubview:classTitleLable];
            
        }
    }
    else if (indexPath.section==3)
    {
        
        Article *article =[Article  mj_objectWithKeyValues:_articleArr[indexPath.row] ];
        if ([article.content_type isEqualToString:@"00"]) {
            CGFloat headerImageH = 164*kScale;
            UIImageView *headerImage = [[UIImageView alloc]init];
            headerImage.frame = CGRectMake(30*kScale, 30*kScale, headerImageH, headerImageH);
            [headerImage sd_setImageWithURL:[NSURL URLWithString:article.cover_img] width:140 height:140];
            
            headerImage.layer.masksToBounds  = YES;
            [cell addSubview:headerImage];
            CGFloat typeLableH = 41*kScale;
            UILabel *typeLable = [[UILabel alloc]initWithFrame:CGRectMake(0 , 0, typeLableH, typeLableH)];
            typeLable.textColor = [UIColor whiteColor];
            typeLable.backgroundColor = QINGColor;;
            typeLable.text = @"话";
            
            typeLable.textAlignment = NSTextAlignmentCenter;
            [headerImage addSubview:typeLable];
            UILabel *introdocLable = [[UILabel alloc]init];
            introdocLable.font = [UIFont systemFontOfSize:13];
            introdocLable.numberOfLines = 0;
            //        introdocLable.lineBreakMode =  NSLineBreakByTruncatingTail;
            introdocLable.textColor = [UIColor colorWithRed:34/255.0 green:34/255.0 blue:34/255.0 alpha:1.0];
            NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc]init];
            style.lineSpacing = 5;
            introdocLable.text = article.content_desc;
            introdocLable.textColor = ZallColorFromRGB(0x444444);
            CGSize introSize = [introdocLable sizeThatFits:CGSizeMake(ScreenW-(headerImageH+3*30*kScale), MAXFLOAT)];
            
            //        NSDictionary *attributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:14], NSParagraphStyleAttributeName:style};
            //        introdocLable.attributedText = [[NSAttributedString alloc]initWithString:introdocLable.text attributes:attributes];
            
            if (introSize.height<headerImageH)
            {
                introdocLable.frame = CGRectMake(headerImageH+2*30*kScale, headerImage.frame.origin.y, ScreenW-(headerImageH+3*30*kScale), introSize.height);
            }
            else
            {
                introdocLable.frame = CGRectMake(headerImageH+2*30*kScale, headerImage.frame.origin.y, ScreenW-(headerImageH+3*30*kScale), headerImageH);
            }
            //            introdocLable.frame = CGRectMake(headerImageH+2*30*kScale, headerImage.frame.origin.y, ScreenW-(headerImageH+3*30*kScale), introSize.height);
            
            [cell addSubview:introdocLable];
            NSDateFormatter  *dateFormatter = [[NSDateFormatter alloc]init];
            //        dateFormatter.dateFormat = @"yyyy-MM-dd HH:mm:ss";
            [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
            NSDate *date = [dateFormatter dateFromString:article.publish_tm];
            NSDateFormatter  *dateFormatter2 = [[NSDateFormatter alloc]init];
            dateFormatter2.dateFormat = @"yyyy/MM/dd";
            UILabel *timeLable= [[UILabel alloc]init];
            timeLable.font = [UIFont systemFontOfSize:13];
            
            timeLable.text =[dateFormatter2 stringFromDate:date];
            
            
            
            CGSize timeLableSize = CGSizeZero;
            
            timeLableSize = [timeLable sizeThatFits:CGSizeMake(MAXFLOAT, 40*kScale)];
            
            timeLable.frame = CGRectMake(30*kScale, headerImage.frame.origin.y+headerImageH+20*kScale,timeLableSize.width, 40*kScale);
            timeLable.textColor = [UIColor colorWithRed:136/255.0 green:136/255.0 blue:136/255.0 alpha:1.0];
            [cell addSubview:timeLable];
            CGFloat btnW = 40*kScale;
//            ZYButton *shareBtn= [[ZYButton alloc]init];
//            [shareBtn setImage:[UIImage imageNamed:@"转发"] forState:UIControlStateNormal];
//            shareBtn.titleLabel.textColor = ZallColorFromRGB(0x666666);
//            CGSize shareBtnSize = CGSizeZero;
//            shareBtnSize = [shareBtn sizeThatFits:CGSizeMake(MAXFLOAT, 40*kScale)];
//            shareBtn.frame = CGRectMake(ScreenW-30*kScale-btnW, headerImage.frame.origin.y+headerImageH+20*kScale,btnW, btnW);
//            [shareBtn addTarget:self action:@selector(shareClick:) forControlEvents:UIControlEventTouchUpInside];
//            [cell addSubview:shareBtn];
            UILabel *thumbCountLable= [[UILabel alloc]init];
            thumbCountLable.font = [UIFont systemFontOfSize:11];
            
            thumbCountLable.text = article.likeCount;
            thumbCountLable.textColor = [UIColor colorWithRed:136/255.0 green:136/255.0 blue:136/255.0 alpha:1.0];
            CGSize thumbCountLableSize = [thumbCountLable sizeThatFits:CGSizeMake(MAXFLOAT, 40*kScale)];
            thumbCountLable.frame = CGRectMake(ScreenW-1*30*kScale-0*btnW-thumbCountLableSize.width, headerImage.frame.origin.y+headerImageH+20*kScale,thumbCountLableSize.width, btnW);
            //        [thumbCountLable sizeToFit];
            [cell addSubview:thumbCountLable];
            
            ZYButton *thumbBtn= [[ZYButton alloc]init];
            [thumbBtn setImage:[UIImage imageNamed:@"取消点赞"] forState:UIControlStateNormal];
            thumbBtn.frame = CGRectMake(ScreenW-1*30*kScale-1*btnW-thumbCountLableSize.width, headerImage.frame.origin.y+headerImageH+20*kScale,btnW, btnW);
            [thumbBtn addTarget:self action:@selector(thumbClick:) forControlEvents:UIControlEventTouchUpInside];
            [cell addSubview:thumbBtn];
            UILabel *commentCountLable= [[UILabel alloc]init];
            commentCountLable.font = [UIFont systemFontOfSize:11];
            
            commentCountLable.text = article.plCount;
            commentCountLable.textColor = [UIColor colorWithRed:136/255.0 green:136/255.0 blue:136/255.0 alpha:1.0];
            CGSize commentCountLableSize = [commentCountLable　 sizeThatFits:CGSizeMake(MAXFLOAT, 40*kScale)];
            commentCountLable.frame = CGRectMake(ScreenW-2*30*kScale-1*btnW-thumbCountLableSize.width-commentCountLableSize.width, headerImage.frame.origin.y+headerImageH+20*kScale,commentCountLableSize.width, btnW);
            [cell addSubview:commentCountLable];
            
            ZYButton *commentBtn= [[ZYButton alloc]init];
            [commentBtn setImage:[UIImage imageNamed:@"评论"] forState:UIControlStateNormal];
            commentBtn.frame = CGRectMake(ScreenW-2*30*kScale-2*btnW-thumbCountLableSize.width-commentCountLableSize.width, headerImage.frame.origin.y+headerImageH+20*kScale,btnW, btnW);
            [cell addSubview:commentBtn];
            
        }
        else if ([article.content_type isEqualToString:@"01"])
        {
            CGFloat headerImageH = 164*kScale;
            UIImageView *headerImage = [[UIImageView alloc]init];
            headerImage.frame = CGRectMake(30*kScale, 30*kScale, headerImageH, headerImageH);
            [headerImage sd_setImageWithURL:[NSURL URLWithString:article.cover_img] width:140 height:140];
            
            headerImage.layer.masksToBounds  = YES;
            [cell addSubview:headerImage];
            CGFloat typeLableH = 41*kScale;
            UILabel *typeLable = [[UILabel alloc]initWithFrame:CGRectMake(0 , 0, typeLableH, typeLableH)];
            typeLable.textColor = [UIColor whiteColor];
            typeLable.backgroundColor = [UIColor blackColor];
            typeLable.text = @"文";
            
            typeLable.textAlignment = NSTextAlignmentCenter;
            [headerImage addSubview:typeLable];
            CGFloat titleImageW = 45*kScale;
            CGFloat titleImageH = 32*kScale;
            UIImageView *titleImage= [[UIImageView alloc]init];
            titleImage.image = [UIImage imageNamed:@"引号"];
            titleImage.frame = CGRectMake(headerImageH+2*30*kScale, headerImage.frame.origin.y+4*kScale,titleImageW, titleImageH);
            [cell addSubview:titleImage];
            UILabel *titleLable= [[UILabel alloc]init];
            titleLable.font = [UIFont systemFontOfSize:15];
            titleLable.text = article.title;
            CGSize titleSize = [titleLable sizeThatFits:CGSizeMake(MAXFLOAT, 40*kScale)];
            titleLable.frame = CGRectMake(headerImageH+2*30*kScale+15*kScale+titleImageW, headerImage.frame.origin.y,ScreenW-(headerImageH+3*30*kScale+15*kScale+titleImageW), 40*kScale);
            [cell addSubview:titleLable];
            
            CGFloat maxH = 48;
            UILabel *introdocLable = [[UILabel alloc]init];
            introdocLable.font = [UIFont systemFontOfSize:13];
            introdocLable.numberOfLines = 3;
            //        introdocLable.lineBreakMode =  NSLineBreakByTruncatingTail;
            introdocLable.textColor = [UIColor colorWithRed:34/255.0 green:34/255.0 blue:34/255.0 alpha:1.0];
            NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc]init];
            style.lineSpacing = 5;
            introdocLable.text = article.content_desc;
            introdocLable.textColor = [UIColor colorWithRed:136/255.0 green:136/255.0 blue:136/255.0 alpha:1.0];
            CGSize introSize = [introdocLable sizeThatFits:CGSizeMake(ScreenW-(headerImageH+3*30*kScale), MAXFLOAT)];
            
            //        NSDictionary *attributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:14], NSParagraphStyleAttributeName:style};
            //        introdocLable.attributedText = [[NSAttributedString alloc]initWithString:introdocLable.text attributes:attributes];
            
            if (introSize.height<maxH)
            {
                introdocLable.frame = CGRectMake(headerImageH+2*30*kScale, headerImage.frame.origin.y+headerImageH-maxH, ScreenW-(headerImageH+3*30*kScale), maxH);
            }
            else
            {
                introdocLable.frame = CGRectMake(headerImageH+2*30*kScale, headerImage.frame.origin.y+headerImageH-maxH, ScreenW-(headerImageH+3*30*kScale), maxH);
            }
            
            [cell addSubview:introdocLable];
            NSDateFormatter  *dateFormatter = [[NSDateFormatter alloc]init];
            //        dateFormatter.dateFormat = @"yyyy-MM-dd HH:mm:ss";
            [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
            NSDate *date = [dateFormatter dateFromString:article.publish_tm];
            NSDateFormatter  *dateFormatter2 = [[NSDateFormatter alloc]init];
            dateFormatter2.dateFormat = @"yyyy/MM/dd";
            UILabel *timeLable= [[UILabel alloc]init];
            timeLable.font = [UIFont systemFontOfSize:13];
            
            timeLable.text =[dateFormatter2 stringFromDate:date];
            
            
            
            CGSize timeLableSize = CGSizeZero;
            
            timeLableSize = [timeLable sizeThatFits:CGSizeMake(MAXFLOAT, 40*kScale)];
            
            timeLable.frame = CGRectMake(30*kScale, headerImage.frame.origin.y+headerImageH+20*kScale,timeLableSize.width, 40*kScale);
            timeLable.textColor = [UIColor colorWithRed:136/255.0 green:136/255.0 blue:136/255.0 alpha:1.0];
            [cell addSubview:timeLable];
            CGFloat btnW = 40*kScale;
//            ZYButton *shareBtn= [[ZYButton alloc]init];
//            [shareBtn setImage:[UIImage imageNamed:@"转发"] forState:UIControlStateNormal];
//            shareBtn.titleLabel.textColor = ZallColorFromRGB(0x666666);
//            CGSize shareBtnSize = CGSizeZero;
//            shareBtnSize = [shareBtn sizeThatFits:CGSizeMake(MAXFLOAT, 40*kScale)];
//            shareBtn.frame = CGRectMake(ScreenW-30*kScale-btnW, headerImage.frame.origin.y+headerImageH+20*kScale,btnW, btnW);
//            [shareBtn addTarget:self action:@selector(shareClick:) forControlEvents:UIControlEventTouchUpInside];
//            [cell addSubview:shareBtn];
//            ZYButton *collecBtn= [[ZYButton alloc]init];
//            [collecBtn setImage:[UIImage imageNamed:@"取消收藏"] forState:UIControlStateNormal];
//            collecBtn.titleLabel.textColor = ZallColorFromRGB(0x666666);
//            CGSize collecBtnSize = CGSizeZero;
//            collecBtnSize = [shareBtn sizeThatFits:CGSizeMake(MAXFLOAT, 40*kScale)];
//            collecBtn.frame = CGRectMake(ScreenW-2*30*kScale-2*btnW, headerImage.frame.origin.y+headerImageH+20*kScale,btnW, btnW);
//            [collecBtn addTarget:self action:@selector(collecClick:) forControlEvents:UIControlEventTouchUpInside];
//            [cell addSubview:collecBtn];
            UILabel *thumbCountLable= [[UILabel alloc]init];
            thumbCountLable.font = [UIFont systemFontOfSize:11];
            
            thumbCountLable.text = article.likeCount;
            thumbCountLable.textColor = [UIColor colorWithRed:136/255.0 green:136/255.0 blue:136/255.0 alpha:1.0];
            CGSize thumbCountLableSize = [thumbCountLable sizeThatFits:CGSizeMake(MAXFLOAT, 40*kScale)];
            thumbCountLable.frame = CGRectMake(ScreenW-1*30*kScale-0*btnW-thumbCountLableSize.width, headerImage.frame.origin.y+headerImageH+20*kScale,thumbCountLableSize.width, btnW);
            //        [thumbCountLable sizeToFit];
            
            [cell addSubview:thumbCountLable];
            
            ZYButton *thumbBtn= [[ZYButton alloc]init];
            [thumbBtn setImage:[UIImage imageNamed:@"取消点赞"] forState:UIControlStateNormal];
            thumbBtn.frame = CGRectMake(ScreenW-1*30*kScale-1*btnW-thumbCountLableSize.width, headerImage.frame.origin.y+headerImageH+20*kScale,btnW, btnW);
            [thumbBtn addTarget:self action:@selector(thumbClick:) forControlEvents:UIControlEventTouchUpInside];
            [cell addSubview:thumbBtn];
            UILabel *commentCountLable= [[UILabel alloc]init];
            commentCountLable.font = [UIFont systemFontOfSize:11];
            
            commentCountLable.text = article.plCount;
            commentCountLable.textColor = [UIColor colorWithRed:136/255.0 green:136/255.0 blue:136/255.0 alpha:1.0];
            CGSize commentCountLableSize = [commentCountLable　 sizeThatFits:CGSizeMake(MAXFLOAT, 40*kScale)];
            commentCountLable.frame = CGRectMake(ScreenW-2*30*kScale-1*btnW-thumbCountLableSize.width-commentCountLableSize.width, headerImage.frame.origin.y+headerImageH+20*kScale,commentCountLableSize.width, btnW);
            [cell addSubview:commentCountLable];
            
            ZYButton *commentBtn= [[ZYButton alloc]init];
            [commentBtn setImage:[UIImage imageNamed:@"评论"] forState:UIControlStateNormal];
            commentBtn.frame = CGRectMake(ScreenW-2*30*kScale-2*btnW-thumbCountLableSize.width-commentCountLableSize.width, headerImage.frame.origin.y+headerImageH+20*kScale,btnW, btnW);
            [cell addSubview:commentBtn];
        }
    }
    else if (indexPath.section==4)
    {
        
    }
    
    
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section==0)
    {
        return  790*kScale;
    }
    else if (indexPath.section==1)
    {
        if (_myStory) {
            return 283*kScale;
        }
        else
        {
            return 100*kScale;
        }
        
    }
    else if (indexPath.section==2)
    {
        return 118*kScale;
    }
    return 294*kScale;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section==0)
    {
        return 0.01;
    }
    else if (section==1)
    {
        return 0.01;
    }
    
    return 24*kScale;
}
//点击cell事件
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 1)
    {
        if (_myStory) {
            //点击进入故事详情
            ArticleWebViewController *avc = [ArticleWebViewController new];
            avc.articleContent = _myStory.content_id;
            avc.articleUserId = _myStory.user_id;
            avc.articleTribeId = _myStory.tribe_id;
            avc.shareimgurl = _myStory.cover_img;
            avc.sharetitle = _myStory.title;
            avc.sharedesc = _myStory.content_desc;
            avc.shareurl = _myStory.shareUrl;
            [self.navigationController pushViewController:avc animated:YES];
        }
        else
        {
            //创建故事
            PublishArticleViewController *vc = [[PublishArticleViewController alloc] initWithNibName:@"PublishArticleViewController" bundle:nil];
            vc.mytype = PublishArticleStory;
            [self.navigationController pushViewController:vc animated:YES];
        }
        
    }
    if (indexPath.section==3) {
        Article *article =[Article  mj_objectWithKeyValues:_articleArr[indexPath.row] ];
        if ([article.content_type isEqualToString:@"01"]) {
            ArticleWebViewController *avc = [ArticleWebViewController new];
            avc.articleContent = article.content_id;
            avc.articleUserId = article.user_id;
            avc.articleTribeId = article.tribe_id;
            avc.shareimgurl = article.cover_img;
            avc.sharetitle = article.title;
            avc.sharedesc = article.content_desc;
            avc.shareurl = article.shareUrl;
            [self.navigationController pushViewController:avc animated:YES];
        } else if ([article.content_type isEqualToString:@"00"]) {
            TopicleWebViewController *avc = [[TopicleWebViewController alloc]initWithNibName:@"TopicleWebViewController" bundle:nil];
            avc.articleContent = article.content_id;
            avc.articleUserId = article.user_id;;
            avc.articleTribeId = article.tribe_id;
            avc.shareimgurl = article.cover_img;
            avc.sharetitle = article.title;
            avc.sharedesc = article.content_desc;
            avc.shareurl = article.shareUrl;
            [self.navigationController pushViewController:avc animated:YES];
        }
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.01;
}
//设置状态栏颜色
- (UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleLightContent;
}
- (void)backClick
{
    [self.navigationController popViewControllerAnimated:YES];
    
}
//点击文章 话题 作品 赞过 评论
- (void) classTitleClick:(ZYButton*)sender
{
    if (sender.tag==10)
    {
        //文章
        ArticleViewController *article = [[ArticleViewController alloc]init];
        [self.navigationController pushViewController:article animated:YES];
        article.type = @"00";
        article.userId = [UserData userid];
    }
    else if (sender.tag==11)
    {
        //话题
        TopicViewController *topic = [[TopicViewController alloc]init];
        [self.navigationController pushViewController:topic animated:YES];
        topic.type = @"00";
        topic.userId = [UserData userid];
    }
    else if (sender.tag==12)
    {
        //赞过
        ZanGuoViewController *zanguo = [[ZanGuoViewController alloc]init];
        [self.navigationController pushViewController:zanguo animated:YES];
        zanguo.type = @"00";
        zanguo.userId = [UserData userid];
        
    }
    else if (sender.tag==13)
    {
        //评论
        HisCommentViewController *vc = [[HisCommentViewController alloc]init];
        vc.userId = [UserData userid];
        [self.navigationController pushViewController:vc animated:YES];
    }
}
//关注
- (void) careBtnClick:(ZYButton*)sender
{
    DYBaseRequest *request = [DYBaseRequest new];
    
    NSString *url = [NSString stringWithFormat:@"%@/hytribe/setConcern?follow_obj_id=%@", APIYIGOU, _user.userId];
    request.requestUrl = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    [request dyBgStartWithCompletionBlockWithSuccess:^(YTKBaseRequest *request) {
        NSDictionary *allDic = [NSDictionary changeType:request.responseJSONObject];
        NSLog(@"1111111%@",allDic);
        //        [self.careBtn setBackgroundColor:[UIColor groupTableViewBackgroundColor]];
        self.careBtn.backgroundColor = ZallColorFromRGB(0x9e9e9e);
        self.careBtn.enabled = NO;
        [ViewFactory showSuccess:@"关注成功"];
    } error:^(YTKBaseRequest *request) {
        NSData *JSONData = [request.responseString dataUsingEncoding:NSUTF8StringEncoding];
        NSDictionary *responseJSON = [NSJSONSerialization JSONObjectWithData:JSONData options:NSJSONReadingMutableLeaves error:nil];
        [ViewFactory showErrorStrMsg:[responseJSON objectForKey:@"message"]];
    } failure:^(YTKBaseRequest *request) {
        [ViewFactory showErrorStrMsg:NETWORK_ERR];
        
    }];
}
//点赞
- (void)thumbClick:(ZYButton*)sender
{
    
}
//收藏
- (void)collecClick:(ZYButton*)sender
{
    
}
//分享
- (void)shareClick:(ZYButton*)sender
{
    
}

- (void)clickMsg {
    EaseConversationListViewController *chatController = [[EaseConversationListViewController alloc] init];
    [self.navigationController pushViewController:chatController animated:YES];
}

@end
